#define _CRT_SECURE_NO_WARNINGS 1
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

struct ListNode
{
	int val;
	struct ListNode* next;
};
//
//ListNode* reverseList(ListNode* head)
//{
//	struct ListNode* prev = NULL;
//	struct ListNode* cur = head;
//	while (cur)
//	{
//		struct ListNode* next = cur->next;
//		cur->next = prev;
//		prev = cur;
//		cur = next;
//	}
//	return prev;
//}
//ListNode* removeNthFromEnd(ListNode* head, int n)
//{
//	assert(head);
//	if (!head)
//	{
//		return NULL;
//	}
//	ListNode* newNode = reverseList(head);
//	ListNode* tmpHead = newNode;
//	while (--n)
//	{
//		newNode = newNode->next;
//	}
//	struct ListNode* newHead = NULL;
//
//	while (tmpHead)
//	{
//		struct ListNode* next = tmpHead->next;
//		if (tmpHead != newNode)
//		{
//			tmpHead->next = newHead;
//			newHead = tmpHead;
//		}
//		tmpHead = next;
//	}
//	return newHead;
//}
//ListNode* swapPairs(ListNode* head)
//{
//	assert(head);
//	struct ListNode* tmpHead = head;
//	struct ListNode* retHead = head;
//	int change = 0;
//	while (tmpHead && tmpHead->next)
//	{
//		if (change % 2)
//		{
//			retHead = tmpHead;
//			retHead = retHead->next;
//		}
//		else
//		{
//			retHead = tmpHead;
//			retHead = retHead->next;
//		}
//		tmpHead = tmpHead->next;
//		++change;
//	}
//	tmpHead->next = NULL;
//}
//struct ListNode* ratateHead(struct ListNode* head)
//{
//	struct ListNode* firsthead = head;
//	struct ListNode* tail = NULL;
//	struct ListNode* tmphead = head;
//	while (tmphead->next)
//	{
//		if (tmphead->next->next == NULL)
//		{
//			tail = tmphead->next;
//			tmphead->next = NULL;
//		}
//		tmphead = tmphead->next;
//	}
//	tail->next = firsthead;
//	firsthead = tail;
//	return firsthead;
//}
//struct ListNode* rotateRight(struct ListNode* head, int k)
//{
//	int len = 0;
//	struct ListNode* tmphead = head;
//	while (tmphead)
//	{
//		++len;
//		tmphead = tmphead->next;
//	}
//	k %= len;
//	tmphead = head;
//	while (k--)
//	{
//		tmphead = ratateHead(head);
//	}
//	head = tmphead;
//	return head;
//}
struct ListNode* deleteNode(struct ListNode* head, int val) {
	struct ListNode* guard = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* tmphead = head;
	head = guard;
	while (tmphead)
	{
		if (tmphead->val != val)
		{
			guard->next = tmphead;
			guard = guard->next;
		}
		tmphead = tmphead->next;
	}
	guard->next = NULL;
	return head->next;
}
void test()
{

	struct ListNode* n1 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n2 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n3 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n4 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n5 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n6 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
	struct ListNode* n7 = (struct ListNode*)calloc(1, sizeof(struct ListNode));

	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = n5;
	n5->next = NULL;

	n1->val = 1;
	n2->val = 2;
	n3->val = 3;
	n4->val = 4;
	n5->val = 5;

	//ListNode* ret = removeNthFromEnd(n1, 2);
	//ListNode* ret = swapPairs(n1);
	struct ListNode* ret = deleteNode(n1, 2);
}
int main()
{
	test();
	return 0;
}